<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title></title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>

    <style>
        .v-enter,
        .v-leave-to {
            opacity: 0;
            transform: translateX(100%);
        }

        .v-enter-active,
        .v-leave-active {
            transition: all 1s ease;
        }

        .v-leave,
        .v-enter-to {
            opacity: 1;
            transform: translateX(0);
        }
    </style>
</head>

<body>
    <div id='app'>
        <a href="#" @click.prevent="isLogin = true">登录</a>
        <a href="#" @click.prevent="isLogin = false">退出登录</a>

        <!-- 
        <login v-show="!isLogin"></login>
        <user-info v-show="isLogin"></user-info> -->

        <!-- <component is="user-info"></component> -->
        <transition mode="out-in">
            <component :is="isLogin?'user-info':'login'"></component>
        </transition>

        <name></name>
    </div>

    <template id="loginTemp">
        <h3>
            登录/注册
        </h3>
    </template>

    <template id="userInfoTemp">
        <div>
            昵称：<name></name>
            名字：孔祥瑞
            <login></login>
        </div>
    </template>

    <script>
        const login = {
            template: '#loginTemp'
        }

        const name = {
            template: '<h3>cyrus</h3>'
        }

        // Vue.component('name', name)

        const userInfo = {
            template: '#userInfoTemp',
            components: {
                name
            }
        }

        // 注册全局组件
        Vue.component('login', login)

        const vm = new Vue({
            el: '#app',
            data: {
                // bool命名一般以is开头
                isLogin: false
            },
            components: {
                // userInfo:userInfo
                userInfo
            }
        })
    </script>
</body>

</html>